/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package cp1300a2;
import java.util.Scanner;

/**
 *
 * @author nick wong
 */
public class Menu {

    static private final String menu_1 = "1. Set Number of horizontal lanes (H-street) [min 1, max 3] \n";
    static private final String menu_2 = "2. Set Number of vertical lanes (V-street) [min 1, max 4] \n";
    static private final String menu_3 = "3. Set Probability of a car entering H-street [min 0, max 1] \n";
    static private final String menu_4 = "4. Set Probability of a car entering V-street [min 0, max 1] \n";
    static private final String menu_5 = "5. Run one simulation cycle \n";
    static private final String menu_6 = "6. Set and run number of simulation cycles [min 1, max 10] \n";

    /**
     * display menu to console
     *
     * @param item which menu item to display. choose from 1 to 6 or 0 to display all menu at once
     */
    public static void display(int item) {

        String output = "";
        switch (item) {
            case 0:
                output += "=== MENU === \n"
                           + menu_1
                           + menu_2
                           + menu_3
                           + menu_4
                           + menu_5
                           + menu_6;
                break;
            case 1:
                output += "=== MENU 1. === \n"
                        + menu_1;
                break;
            case 2:
                output += "=== MENU 2. === \n"
                        + menu_2;
                break;
            case 3:
                output += "=== MENU 3. === \n"
                        + menu_3;
                break;
            case 4:
                output += "=== MENU 4. === \n"
                        + menu_4;
                break;
            case 5:
                output += "=== MENU 5. === \n"
                        + menu_5;
                break;
            case 6:
                output += "=== MENU 6. === \n"
                        + menu_6;
                break;

        }
        output += "Enter your choice: ";
        System.out.print(output);
    }
    /**
     * menu function
     *
     * display menu to user by calling Menu.display and assign user input to Roads.*
     */
    public static void start() {
        int start = 0;
        Scanner input = new Scanner(System.in);

        while (start < 1) {
            Menu.display(0);
            int menu_num = input.nextInt();

            switch (menu_num) {
                case 1:
                    Menu.display(1);
                    Roads.setH_lane(input.nextInt());
                    break;
                case 2:
                    Menu.display(2);
                    Roads.setV_lane(input.nextInt());
                    break;
                case 3:
                    Menu.display(3);
                    Roads.setH_car(input.nextInt());
                    break;
                case 4:
                    Menu.display(4);
                    Roads.setV_car(input.nextInt());
                    break;
                case 5:
                    start = (Menu.menuCheck() == true) ? 1 : 0;
                    //start = 1;
                    break;
                case 6:
                    Menu.display(6);
                    Roads.setCycles(input.nextInt());
                    break;
            }
        }
    }
    /**
     * menu checker function
     *
     * check if all required input from user has
     *
     * @return true if all good, if still require input then return false and display error msg
     */
    public static Boolean menuCheck() {
        String error = "";
        error += (Roads.getH_lane() < 0) ? "Menu 1 not set \n" : "" ;
        error += (Roads.getV_lane() < 0) ? "Menu 2 not set \n" : "" ;
        error += (Roads.getH_car() < 0) ? "Menu 3 not set \n" : "" ;
        error += (Roads.getV_car() < 0) ? "Menu 4 not set \n" : "" ;
        error += (Roads.getCycles() < 0) ? "Menu 6 not set \n" : "" ;
        if (error.equals("")) {
            return true;
        } else {
            System.out.println(error);
            return false;
        }
    }
}
